package com.wanji.sdk.impl.http;

import com.wanji.protocol.api.ByteBufEncoder;
import com.wanji.protocol.api.DeviceMessageDecoder;
import com.wanji.protocol.api.Protocol;
import com.wanji.protocol.api.ProtocolTemplate;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

public class HttpProtocol extends ProtocolTemplate {

    @Override
    public String protocolType() {
        return "HTTP";
    }

    @Override
    protected DeviceMessageDecoder<?> createDecoder() {
        return new HttpMessageDecoder();
    }

    @Override
    protected ByteBufEncoder<?> createEncoder() {
        return new HttpMessageEncoder();
    }

    @Override
    protected void initPipeline(ChannelPipeline pipeline) {
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(65536));
    }

    @Override
    public Protocol clone() {
        return super.clone();
    }
}
